$(function() {
	layui.use(['form', 'element', 'util', 'layer','laypage'], function() {
		var form = layui.form;
		form.render();
		var util = layui.util;
		var layer = layui.layer;
		var element = layui.element;
		var laypage=layui.laypage;
		var sum;
		
		
		
		function find_role_list(page, rows) {
			$.ajax({
				type: "get",
				url: "http://localhost:8080/ssmService/role/selectPageRole",
				async: "false",
				data: {
					"queryParams.curr_page": page,
					"queryParams.curr_size": rows
				},
				"success": function(result) {
					
					if(result.resultCode == 0) {
						sum=result.data.total;
						a(sum);
						show(result);
					}
				},
				"error": function() {

				}
			});
		}

		//页面的渲染模块
		function show(result) {
			
			var roleList = result.data.list;
			$(".table_tbody").empty();
			$.each(roleList, function(index, item) {
				var tr = $("<tr></tr>"); //写$()的作用是
				var td1 = "<td><input type='checkbox' role_id=" + item.role_id + " lay-skin='primary'></td>";
				var td2 = "<td>" + item.name + "</td>";
				var td3 = "<td>" + item.memo + "</td>";
				var td4 = "<td>" + item.update_user_name + "</td>";
				var time=util.toDateString(item.update_time,"yyyy-MM-dd HH:mm:ss");
				var td5 = "<td>"+time+"</td>";
				var td6 = "<td><a href='#' role_id='" + item.role_id + "' class='layui-btn layui-btn-sm updateRole'>编辑</a>" +
					"<a href='#' role_id='" + item.role_id + "' class='layui-btn layui-btn-sm layui-btn-danger'>删除</a></td>";

				tr.append(td1,td2,td3,td4,td5,td6);
				$(".table_tbody").append(tr);
			});
			form.render();
		}
		find_role_list(1,10);
		
		
		function  a(sum){
			laypage.render({
			    elem: 'table_page',
			    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
			    count: sum,
			    jump:function(obj,first){
			    	if(!first){
			    		find_role_list(obj.curr,obj.limit);
			    	}
			    }
			 });
		}
		
		
		
		
		
		
		

		$(".addRole").click(function() {
			layer.open({
				type: 2,
				title: '新增角色信息',
				shadeClose: true,
				shade: 0.8,
				area: ['70%', '90%'],
				content: 'addRole.html'
			});
			layer.full(index);  //使弹出层全屏化。
		});

		$(".updateRole").click(function() {
			layer.open({
				type: 2,
				title: '修改角色信息',
				shadeClose: true,
				shade: 0.8,
				area: ['70%', '90%'],
				content: 'updateRole.html'
			});
		});
	});
})